package cn.iotab.iotkit.server.demo.device.handler;

import cn.iotab.iotkit.transport.api.access.device.listener.DevicePropertyPushHandler;
import cn.iotab.iotkit.transport.api.access.model.custom.property.PropertyPushMessage;
import cn.iotab.iotkit.transport.api.access.model.custom.property.PropertyPushMessageReply;
import cn.iotab.iotkit.transport.api.access.model.message.DeviceMessageReply;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 设备向平台pushProperty，可用于设备向平台上报配置、状态信息
 * 请求示例：
 * <pre>
 * {
 *   "id": "123",
 *   "ver": "1.0",
 *   "ack":1,
 *   "type": "prop.push",
 *   "param": {
 *     "props": {"key1":"value1","key2":"value2"}
 *   }
 *  }
 *  </pre>
 * 响应示例:
 * {"code":200,"id":"123"}
 */
@Slf4j
@Component
public class MyDevicePropertyPushHandler extends DevicePropertyPushHandler {
    @Override
    protected ListenableFuture<DeviceMessageReply> doProcess(PropertyPushMessage message) {
        log.info("receive PropertyPushMessage: {}", message.toOriginMessage());
        //
        PropertyPushMessageReply reply = new PropertyPushMessageReply();
        reply.from(message);
        reply.setSuccess();
        return Futures.immediateFuture(reply);
    }
}
